﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Http.Controllers;
using System.Web.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ActionFilterAttribute = System.Web.Http.Filters.ActionFilterAttribute;

namespace API.App_Start
{
    public class Filters : ActionFilterAttribute
    {
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var c = actionContext.ControllerContext.Request.Properties["MS_HttpContext"] as HttpContextWrapper;//获取httpcontextWrapper对象
            var stream = actionContext.Request.Content.ReadAsStreamAsync().Result;
            var encoding = Encoding.UTF8;
            stream.Position = 0;
            var responseData = "";
            //如果没有指定Headers 直接解析postData 文件流
            using (var reader = new StreamReader(stream, encoding))
            {
                responseData = reader.ReadToEnd();
                JObject json = JObject.Parse(responseData);
                //JObject postData = (JObject)JsonConvert.DeserializeObject(responseData);
            }
            if (c != null)
            {
                //若指定Headers,则直接使用reques对象
                var result = c.Request["sign"];
            }
            base.OnActionExecuting(actionContext);
        }
    }
}